from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView

class PathHtml(BrowserView):

    def getCategoryContents(self):  
        """
        Perform a search returning all content tems matching the category value
        """ 
             
        reqCategory = self.getCategoryName()
        
        portal_catalog = getToolByName(self, 'portal_catalog')
        query = {}
        query['resourcecategorypath '] = reqCategory # Does not seem to work
        
        results = portal_catalog.searchResults(query)
        results_list = []
        
        # Check if the object is tagged with the given category
        for result in results:
            if hasattr(result, 'resourcecategorypath'):
                cat_path = str(result.resourcecategorypath)
                if cat_path is not '':
                    if reqCategory.lower() in cat_path.lower(): 
                        results_list.append(result)
        
        return results_list
        
    def getCategoryName(self):
        """
        Return the category name passed
        """
        return str(self.request.form["category"])
    
